<template>
	<view class="full-page" v-if="totalPage">
		
	</view>
	<view class="content" v-else>
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="我的粉丝" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="tobox"> 
			<view class="serbox">
				<image :src="'/images/search.png' | formatImgUrl" class="serpic" mode=""></image>
				<input type="text" @confirm="getList(true)" class="serput" v-model="keyword" placeholder="搜索">
			</view>
			<view class="totxt" @click="clearInput">
				取消
			</view>
		</view>
		
		
		<view class="empytView" v-if="!list.total">
			<image :src="'/images/kong.png' | formatImgUrl" mode="widthFix" />
			<!-- <view>- 空列表 -</view> -->
		</view>
		<view class="wubox">
			<view class="total-num" v-if="list.total">
				共 <text>{{list.total}}</text> 个粉丝
			</view>
			<view class="wuli" v-for="(item, index) in rowList" @click="$go('/pages/my/my?id='+item.user.membe_id)">
				<image :src="item.user.pic | formatImgUrl" class="wuhead" mode=""></image>
				<view class="wucen">
					<view class="wutitle">
						{{item.user.username}}
					</view>
					<view class="wutxt oneline">
						{{item.user.signature_des?item.user.signature_des:'暂无签名'}}
					</view>
				</view>
				<view class="back" @click.stop="id = item.user.membe_id,userLike()" v-if="!item.user.is_like">
					回关
				</view>
				<view class="wusub" v-else @click.stop="id = item.user.membe_id,show = true">
					<image :src="'/images/dian.png' | formatImgUrl" class="dian" mode=""></image>
					<view class="yitxt">
						已互粉
					</view>
				</view>
			</view>

		</view>
		<!-- 取消关注 -->
		<u-popup :show="show" @close="close" @open="open">
			<view class="mask">
				<view class="matop" @click="userLike()">
					<view class="matxt">
						取消关注
					</view>
					<image :src="'/images/rarr.png' | formatImgUrl" class="mapic" mode=""></image>
				</view>
				<view class="qubox" @click="show = false">
					取消
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 取消关注
				show: false,
				guanList: [],
				// 输入框
				keyword: '',
				id: 0,
				list: {},
				page: 1,
				rowList: [],
				totalPage: true
			}
		},
		onLoad() {

		},
		onShow() {
			this.getList()
		},
		// 上拉加载
		onReachBottom() {
			if (this.list.current_page < this.list.last_page) {
				this.page++; // 页数加一，加载下一页数据
				this.getList();
			}
		},
		methods: {
			userLike() {
				this.$api.default.request('user/userLike', {
					uid: this.id,
				}, 'POST').then((res) => {
					if (res.code == 1) {
						this.$common.successToShow(res.msg, () => {
							this.page = 1
							this.getList()
							this.show = false
						})
					}
				})
			},
			getList(isSearch = false) {
				if(isSearch){
					this.page = 1
				}
				this.$api.default.request('user/userFans', {
					type: 1,
					uid: this.uid,
					keyword:this.keyword,
					page: this.page
				}, 'POST').then((res) => {
					if (res.code == 1) {
						this.list = res.data
						if (res.data.current_page > 1) {
							res.data.data.forEach((item) => {
								this.rowList.push(item)
							})
						} else {
							this.rowList = res.data.data
						}
					}
					
					this.totalPage = false
				})
			},
			// 搜索清空
			clearInput() {
				this.inputValue = '';
			},
			// 进入搜索
			search() {
				console.log("搜索操作");
			},
			// 关注
			open() {

			},
			close() {
				this.show = false
			},
			quHide(index) {
				console.log(this.guanList[index])
				this.guanList[index].guanzhu = !this.guanList[index].guanzhu
			},
			quxiao() {
				this.show = false
				this.guanList[this.selIndex].guanzhu = !this.guanList[this.selIndex].guanzhu
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		.tobox {
			padding: 20rpx 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #ffffff;

			.serbox {
				width: 564rpx;
				display: flex;
				align-items: center;
				background: #F8F8F8;
				border-radius: 142px;
				height: 72rpx;
				padding: 0 26rpx;

				.serpic {
					width: 32rpx;
					height: 32rpx;
					flex-shrink: 0;
				}

				.serput {
					padding: 0 16rpx;
					width: 500rpx;
					font-size: 28rpx;
					color: #333333;
				}
			}

			.totxt {
				font-size: 28rpx;
				font-weight: normal;
				letter-spacing: 0em;
				color: #3D3D3D;
			}
		}

		.wubox {
			background-color: #ffffff;
			padding: 6rpx 60rpx 0;

			.wuli {
				border-bottom: none;
			}

			.wuli {
				height: 120rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.wuhead {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					flex-shrink: 0;
				}

				.wucen {
					flex-grow: 1;
					padding-left: 12rpx;

					.wutitle {
						padding-bottom: 5rpx;
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
					}

					.wutxt {
						width: 340rpx;
						font-size: 20rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #999999;
					}
				}

				.wusub {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 144rpx;
					height: 48rpx;
					background: #F8F8F8;
					border-radius: 25rpx;

					.dian {
						width: 32rpx;
						height: 32rpx;
					}

					.yitxt {
						font-size: 24rpx;
						color: #999999;
					}
				}

				.back {
					width: 144rpx;
					height: 48rpx;
					box-sizing: border-box;
					border: 1px solid #45C4B0;
					border-radius: 25rpx;
					font-size: 24rpx;
					color: #45C4B0;
					text-align: center;
					line-height: 48rpx;
				}
			}
		}

		.mask {
			background: #F2F5F2;
			border-top-left-radius: 8px;
			border-top-right-radius: 8px;
			overflow: hidden;

			.matop {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 40rpx 68rpx;
				margin-bottom: 20rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
				background-color: #ffffff;

				.mapic {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}

				.matxt {
					flex-grow: 1;
					font-size: 28rpx;
					padding: 0 16rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
				}
			}

			.qubox {
				line-height: 120rpx;
				text-align: center;
				font-size: 28rpx;
				font-weight: bold;
				letter-spacing: 0em;
				color: #3D3D3D;
				height: 120rpx;
				opacity: 1;
				background: #FFFFFF;
			}
		}

	}
	
	.total-num{
		font-size: 10px;
		color: #999999;
		
		text{
			margin: 0 10rpx;
			color: #3D3D3D;
		}
	}
</style>